package world.snowcrystal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import world.snowcrystal.dao.Article;
import world.snowcrystal.service.ArticleProvideService;

import java.util.List;

@Controller
@RequestMapping(value = "/articles",
        produces = MediaType.APPLICATION_JSON_VALUE)
public class JdbcArticleProvideController {

    public static final int DEFAULT_PROVIDE_HOT_NUMBER = 4;

    @Autowired
    private ArticleProvideService articleProvideService;
    @GetMapping("/{all}/{abstract}")
    public HttpEntity<Article> getArticle(String all) {
        return null;
    }

    @GetMapping("/hotArticles")
    public HttpEntity<List<Article>> getHotArticles(
            @RequestParam(value = "requireProvideThumbnail", required = false)
            boolean requireProvideThumbnail,
            @RequestParam(value = "topN", required = false)
        Integer topN) {
        List<Article> articles = articleProvideService.getArticlesByViewCountDesc(topN == null ? DEFAULT_PROVIDE_HOT_NUMBER : topN);
        return ResponseEntity.ok(articles);
    }


}
